<template>
  <div class="itemsView">
    <div class="itemHeader">
      <div class="title">
        <slot name="title"></slot>
      </div>
      <span>查看全部 ></span>
    </div>
    <ul class="list">
      <li v-for="item in newsList" :key="item.id" @click="handerfn(item.id)">
        <img :src="item.picture" class="image" />
        <div class="bottomOne" v-if="item.name">
          <span class="title">{{ item.name }}</span>
          <span class="price">{{ item.price }}</span>
        </div>
        <div class="bottomTwo" else>
          <span class="title">{{ item.title }}</span>
          <span class="price">{{ item.alt }}</span>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  props: ["newsList"],
  methods: {
    // 跳转详情页
    handerfn(id) {
      this.$router.push({ path: "/home/details", query: { id } });
    },
  },
};
</script>

<style lang = "scss" scoped>
.itemsView {
  padding: 0 140px;
  .itemHeader {
    padding: 40px 0;
    display: flex;
    justify-content: space-between;
    .title {
      display: flex;
      align-items: flex-end;
      h3 {
        font-size: 32px;
        font-weight: 400;
        margin-left: 6px;
        height: 35px;
        line-height: 35px;
      }
      span {
        font-size: 16px;
        color: #999;
        margin-left: 20px;
      }
    }
    span {
      color: #333;
    }
  }
  .list {
    display: flex;
    justify-content: space-between;
    li {
      width: 306px;
      height: 406px;
      transition: all 0.5s;
      &:hover {
        transform: translateY(-5px);
        box-shadow: 7px 7px 4px #f3f3f3;
      }
      .image {
        width: 100%;
      }
      .bottomOne {
        padding: 10px 0;
        display: flex;
        flex-direction: column;
        justify-content: center;
        background: #f0f9f4;
        .title {
          font-size: 22px;
          padding: 12px 30px 0 30px;
          text-align: center;
          text-overflow: ellipsis;
          overflow: hidden;
          white-space: nowrap;
        }
        .price {
          font-size: 22px;
          padding: 12px 30px 0 30px;
          text-align: center;
          color: #cf4444;
        }
      }
      .bottomTwo {
        margin: 0 auto;
        display: flex;
        flex-direction: column;
        justify-content: center;
        .title {
          font-size: 22px;
          padding-top: 12px;
          text-align: center;
        }
        .price {
          color: #999;
          font-size: 18px;
          padding-top: 12px;
          text-align: center;
        }
      }
    }
  }
}
</style>